import request from '@/api/axios'
import {AxiosPromise} from 'axios'
import {DataRes} from '@/api/config'
import {GeneralCondition} from './generalSituation'
import {LifeStyle} from './lifeStyle'
import {VisceraFunction} from './visceraAbility'
import {CheckBody} from './checkBody'
import {MainHealthProblems} from './mainHealthProblems'
import {BasePhysicalExamination} from './index'

// 项目明细
export interface ItemData {
  label: string // 体检项目名称
  key: string // 体检项目键
  value?: string | number // 体检项目值
  unit?: string // 单位
  printSort?: number //打印排序
}

// 信息总结
export interface InforSummaryList {
  title: string // 大类名称
  key: string // 大类键
  data: Array<ItemData> // 项目明细
  sort?: number //打印排序
  minWidth?: string // 表头最小宽度
}

// 信息总结数据
export interface InforSummary {
  generalConditionVO?: GeneralCondition // 一般状况
  lifeStyleVO?: LifeStyle // 生活方式
  visceraFunctionVO?: VisceraFunction // 脏器功能
  checkBodyVO?: CheckBody // 查体
  healthyDiseaseVO?: MainHealthProblems // 现存主要健康问题
}

export interface SmartEva {
  id: string // id
  name: string // 规则名称
  healthGuide: string //健康指导
  dangerousControl: string // 危险因素控制JSON
  guideCheckboxValue: string // 健教指导JSON
  isException?: boolean // 是否纳入异常
}

// 健康评价
export interface HealthEvaluation extends BasePhysicalExamination {
  abnorSign: string // 健康评价
  healthGuide: string | null // 健康指导
  riskControl: string | null // 危险因素控制
  guideSelected: Array<string> // 健教指导勾选
  guideGrade?: string | null // 健教指导勾选字符串
  guideValue: string | null // 健教指导内容
  abnormal?: string // 体检有无异常
  evaluationCheckbox: Array<string> // 健康评价
  abnormalOne?: string | null // 异常1
  abnormalTwo?: string | null // 异常1
  abnormalThree?: string | null // 异常1
  abnormalFour?: string | null // 异常1
  healthCoaching: Array<string> // 健康指导
  riskFactorControlCheckbox: Array<string> // 危险因素控制
  targetWeight?: number // 减体重
  vaccinesInfo?: string | null // 建议接种疫苗
  otherInfo?: string | null // 其他危险因素控制
  abnormalId?: string | null // 健康智能评价异常信息id
}

// 摘除后端不要的属性
export type HealthEvaluationParams = Omit<HealthEvaluation, 'evaluationCheckbox' | 'healthCoaching' | 'riskFactorControlCheckbox' | 'guideSelected'>

// 信息总结基础数据
export const inforSummaryData: Array<InforSummaryList> = [
  {
    title: '一般状况',
    key: 'generalConditionVO',
    data: [
      {label: '症状', key: 'sympromName', value: '', printSort: 8},
      {label: '体温', key: 'tempera', value: '', unit: '℃', printSort: 9},
      {label: '脉率', key: 'pulseRate', value: '', unit: '次/分钟', printSort: 10},
      {label: '呼吸频率', key: 'breathRate', value: '', unit: '次/分钟', printSort: 11},
      {label: '收缩压(左)', key: 'sbpLeft', value: '', unit: 'mmHg', printSort: 4},
      {label: '舒张压(左)', key: 'dbpLeft', value: '', unit: 'mmHg', printSort: 5},
      {label: '收缩压(右)', key: 'sbpRight', value: '', unit: 'mmHg', printSort: 6},
      {label: '舒张压(右)', key: 'dbpRight', value: '', unit: 'mmHg', printSort: 7},
      {label: '身高', key: 'height', value: '', unit: 'cm', printSort: 1},
      {label: '体重', key: 'weight', value: '', unit: 'kg', printSort: 2},
      {label: '腰围', key: 'waist', value: '', unit: 'cm', printSort: 12},
      {label: '体质指数(BMI)', key: 'bmi', value: '', unit: 'kg/m²', printSort: 3},
      {label: '老年人健康状态自我评估', key: 'odSelfevalStateName', value: '', printSort: 13},
      {label: '老年人生活自理能力自我评估', key: 'odSelfcareStateName', value: '', printSort: 14},
      {label: '老年人认知功能', key: 'odCognStateName', value: '', printSort: 15},
      {label: '老年人情感状态', key: 'odEmotionStateName', value: '', printSort: 16}
    ]
  },
  {
    title: '生活方式',
    key: 'lifeStyleVO',
    data: [
      {label: '锻炼频率', key: 'exerFreqStateName', value: ''},
      {label: '每次锻炼时间', key: 'perExerTime', value: '', unit: '分钟'},
      {label: '坚持锻炼时间', key: 'insExerTime', value: '', unit: '年'},
      {label: '锻炼方式', key: 'exerMethod', value: ''},
      {label: '饮食习惯', key: 'eatHabitName', value: ''},
      {label: '吸烟状况', key: 'smokeStateName', value: ''},
      {label: '日吸烟量', key: 'dailySmokeSum', value: '', unit: '支'},
      {label: '开始吸烟年龄', key: 'startSmorkeAge', value: '', unit: '岁'},
      {label: '戒烟年龄', key: 'quitSmorkeAge', value: '', unit: '岁'},
      {label: '饮酒频率', key: 'drinkFreqStateName', value: ''},
      {label: '日饮酒量', key: 'dailyDrinkSum', value: '', unit: '两'},
      {label: '开始饮酒年龄', key: 'startDrinkAge', value: '', unit: '岁'},
      {label: '近一年内是否曾醉酒', key: 'drunkState', value: ''},
      {label: '是否戒酒', key: 'quitDrinkStateName', value: ''},
      {label: '戒酒年龄', key: 'quitDrinkAge', value: '', unit: '岁'},
      {label: '饮酒种类', key: 'drinkTypeName', value: ''},
      {label: '职业病危害因素接触史', key: 'occupaHist', value: ''},
      {label: '工种', key: 'workTypeName', value: ''},
      {label: '从业时间', key: 'ageLimit', value: '', unit: '年'},
      {label: '毒物种类', key: 'poisonTypeName', value: ''},
      {label: '防护措施', key: 'securityTypeName', value: ''}
    ]
  },
  {
    title: '脏器功能',
    key: 'visceraFunctionVO',
    data: [
      {label: '口唇', key: 'oralCavityName', value: ''},
      {label: '齿列', key: 'dentalArchName', value: ''},
      {label: '咽部', key: 'pharynxStateName', value: ''},
      {label: '视力（左）', key: 'eyesLeft', value: ''},
      {label: '视力（右）', key: 'eyeRight', value: ''},
      {label: '矫正视力（左）', key: 'recEyeLeft', value: ''},
      {label: '矫正视力（右）', key: 'recEyeRight', value: ''},
      {label: '听力', key: 'hearingStateName', value: ''},
      {label: '运动功能', key: 'motorFuncStateName', value: ''}
    ]
  },
  {
    title: '查体',
    key: 'checkBodyVO',
    data: [
      {label: '眼底', key: 'eyeGroundStateName', value: ''},
      {label: '皮肤', key: 'skinStateName', value: ''},
      {label: '巩膜', key: 'cornOpacStateName', value: ''},
      {label: '淋巴结', key: 'lympGlanStateName', value: ''},
      {label: '桶状胸', key: 'barrelChestStateName', value: ''},
      {label: '呼吸音', key: 'breathSoundStateName', value: ''},
      {label: '罗音', key: 'raleStateName', value: ''},
      {label: '心率', key: 'heartRate', value: '', unit: '次/分钟'},
      {label: '心律', key: 'rhythmStateName', value: ''},
      {label: '杂音', key: 'murmurStateName', value: ''},
      {label: '压痛', key: 'tendernessStateName', value: ''},
      {label: '包块', key: 'massStateName', value: ''},
      {label: '肝大', key: 'hapaStateName', value: ''},
      {label: '脾大', key: 'spleStateName', value: ''},
      {label: '移动性浊音', key: 'shiftDullStateName', value: ''},
      {label: '下肢水肿', key: 'edemaExtrStateName', value: ''},
      {label: '足背动脉搏动', key: 'arteStateName', value: ''},
      {label: '肛门指诊', key: 'digtExamStateName', value: ''},
      {label: '乳腺', key: 'breastName', value: ''},
      {label: '外阴', key: 'vulvaStateName', value: ''},
      {label: '阴道', key: 'vaginoStateName', value: ''},
      {label: '宫颈', key: 'cervicalStateName', value: ''},
      {label: '宫体', key: 'palaceStateName', value: ''},
      {label: '附件', key: 'annexaUteriStateName', value: ''},
      {label: '查体其他', key: 'bodyOther', value: ''}
    ]
  },
  {
    title: '现存主要健康问题',
    key: 'healthyDiseaseVO',
    data: [
      {label: '脑血管疾病', key: 'cereDiseName', value: ''},
      {label: '肾脏疾病', key: 'kidneyDiseName', value: ''},
      {label: '心脏疾病', key: 'heartDiseName', value: ''},
      {label: '血管疾病', key: 'vascuDiseName', value: ''},
      {label: '眼部疾病', key: 'eyeDiseName', value: ''},
      {label: '神经系统疾病', key: 'nervousDiseName', value: ''},
      {label: '其他系统疾病', key: 'otherDiseName', value: ''}
    ]
  }
]

/**
 * @description: 获取左侧信息总结
 * @param {string} checkupRegisterId
 * @return {*}
 */
export const getHealthyAppraiseInfo = (checkupRegisterId: string): AxiosPromise<DataRes<InforSummary>> => {
  return request({
    url: `/api/healthyAppraise/getHealthyAppraiseInfo/${checkupRegisterId}`,
    method: 'get'
  })
}

/**
 * @description: 根据体检登记表id获取健康评价
 * @param {string} checkupRegisterId
 * @return {*}
 */
export const getHealthEvaluation = (checkupRegisterId: string): AxiosPromise<DataRes<HealthEvaluation>> => {
  return request({
    url: `/api/healthyAppraise/get/${checkupRegisterId}`,
    method: 'get'
  })
}

/**
 * @description: 保存健康评价
 * @param {HealthEvaluation} data
 * @return {*}
 */
export const saveHealthEvaluation = (data: HealthEvaluationParams): AxiosPromise<DataRes<undefined>> => {
  return request({
    url: '/api/healthyAppraise/save',
    method: 'post',
    data
  })
}

/**
 * @description: 智能评价
 * @param {string} checkupRegisterId 体检登记表id
 * @return {*}
 */
export const smartEva = (checkupRegisterId: string): AxiosPromise<DataRes<Array<SmartEva>>> => {
  return request({
    url: `/api/healthyAppraise/smartEva/${checkupRegisterId}`,
    method: 'post'
  })
}
